<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/11/7
 * Time: 18:03
 */

namespace Admin\Model;
use Think\Model;

class MemberRelativeModel extends Model
{
    protected $trueTableName='t_user_relative';

    public function getNextAll($role_id, $id){
        switch($role_id){
            case 101:
                $result = $this->where('dean_id='.$id)->count();
                break;
            case 102:
            case 103:
            case 104:
                $result = $this->where('expand_id='.$id)->count();
                break;
            case 105:
                $result = $this->where('teacher_id='.$id)->count();
                break;
            case 106:
                $result = $this->where('parent_id='.$id)->count();
                break;
            default:
                return -1;
        }
        return $result;
    }

    public function getIds($id, $role_id, &$p){
        switch($role_id){
            case 101:
                $result = $this->where('dean_id='.$id)->page($p,C('PAGE_COUNT'))->field('user_id')->select();
                $count = $this->where('dean_id='.$id)->count();
                break;
            case 102:
            case 103:
            case 104:
                $result = $this->where('expand_id='.$id)->page($p,C('PAGE_COUNT'))->field('user_id')->select();
            $count = $this->where('expand_id='.$id)->count();
                break;
            case 105:
                $result = $this->where('teacher_id='.$id)->page($p,C('PAGE_COUNT'))->field('user_id')->select();
                $count = $this->where('teacher_id='.$id)->count();
                break;
            case 106:
                $result = $this->where('parent_id='.$id)->page($p,C('PAGE_COUNT'))->field('user_id')->select();
                $count = $this->where('parent_id='.$id)->count();
                break;
            default:
                return -1;
        }
        $page   = new \Think\Page($count,C('PAGE_COUNT'));
        $p  = $page->angular_show();
        return $result;
    }

    public function getRelations($id){
        return $this->where('user_id='.$id)->find();
    }
    /**
     * 修改推销员上级
     */
    public function edit_dean($uid, $did){
        $result=$this->where('user_id='.$uid)->setField('dean_id',$did);
        $this->where('expand_id='.$uid)->setField('dean_id',$did);
        return $result;
    }
    /* 精确查找 */
    public function searchOne($map){
        return $this->field('user_id')->where($map)->select();
    }
}